package edu.ynu.se.xiecheng.achitectureclass.controller;

import edu.ynu.se.xiecheng.achitectureclass.common.controller.LogicController;
import edu.ynu.se.xiecheng.achitectureclass.dao.BusinessDao;
import edu.ynu.se.xiecheng.achitectureclass.entity.Business;
import edu.ynu.se.xiecheng.achitectureclass.entity.Item;
import edu.ynu.se.xiecheng.achitectureclass.entity.Oorder;
import edu.ynu.se.xiecheng.achitectureclass.entity.Shop;
import edu.ynu.se.xiecheng.achitectureclass.service.BusinessService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.modelmapper.ModelMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Set;

@Api(tags = "business实体的控制器")
@RestController
@RequestMapping("/business")
public class BusinessController extends LogicController<BusinessService, BusinessDao,Business,Long> {
    public BusinessController(@Autowired BusinessService ss){
        super(ss);
    }

    @ApiOperation("商家创建门店")
    @GetMapping("/addShop/{businessId}/{shopName}")
    public Business addShop(@PathVariable Long businessId, @PathVariable String shopName){
        return getService().addShop(businessId,shopName);
    }
    @ApiOperation("商家查看家门店所有订单")
    @GetMapping("/watchOrders/{businessId}")
    public Set<Oorder> watchOrders(@PathVariable Long businessId){
        return getService().listOrders(businessId);
    }

    @ApiOperation("商家创建商品")
    @PostMapping("/createItem")
    public Item createItem(@RequestParam String itemName){
        return getService().createItem(itemName);
    }

    @ApiOperation("商家确认某家门店订单")
    @GetMapping("/confirmOrders/{businessId}/{shopId}/{orderId}")
    public Oorder confirmOrders(@PathVariable Long businessId, @PathVariable Long shopId, @PathVariable Long orderId){
        return getService().confirmOrder(businessId,shopId, orderId);
    }

    @ApiOperation("商家退款某家门店订单")
    @GetMapping("/refund/{businessId}/{shopId}/{orderId}")
    public Oorder refund(@PathVariable Long businessId, @PathVariable Long shopId, @PathVariable Long orderId){
        return getService().refund(businessId,shopId, orderId);
    }

    @ApiOperation("用户注册")
    @PostMapping ("/register")
    public Business register(@RequestParam String username, @RequestParam String password){
        return getService().register(username,password);
    }
    @ApiOperation("用户登录")
    @PostMapping ("/login")
    public Business login(@RequestParam String username, @RequestParam String password){
        return getService().login(username,password);
    }

}
